package com.tyut.controller;

import com.tyut.pojo.*;
import com.tyut.service.EditorService;
import com.tyut.service.impl.ArticleServiceImpl;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController
@RequestMapping("/editor")
public class EditorController {
	@Autowired
	private EditorService editorService;

	@Autowired
	private ArticleServiceImpl articleService;
	@PutMapping
	public Result update(@RequestBody Article article){
		articleService.update(article);
		return Result.success();
	}

	@GetMapping
	public Result<PageBean<Article>> list(Integer pageNum, Integer pageSize, @RequestParam(required = false) Integer categoryId, @RequestParam(required = false) String state, @RequestParam(required = false) String checkState){
		PageBean<Article> pageBean = editorService.list(pageNum,pageSize,categoryId, state,checkState);
		return Result.success(pageBean);
	}

	@GetMapping("/category")
	public Result<List<Category>> list(){
		List<Category> category = editorService.findAll();
		return Result.success(category);
	}

	@GetMapping("/all")
	public Result<PageBean<Editor>> GetUser(Integer pageNum, Integer pageSize,String username){
		PageBean<Editor> pageBean = editorService.editorlist(pageNum,pageSize,username);
		return Result.success(pageBean);
	}
}
